//
//  MakeSureTheOrderOneTableViewCell.m
//  BaseFrame
//
//  Created by 吕金状 on 2017/8/11.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "MakeSureTheOrderOneTableViewCell.h"

@interface MakeSureTheOrderOneTableViewCell ()

Strong UILabel *titleLabel;
Strong UIImageView *titleImageView;
Strong UIView *lineView;

@end

@implementation MakeSureTheOrderOneTableViewCell

- (id)initWithCellIdentifier:(NSString *)cellID{
    self = [super initWithCellIdentifier:cellID];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        _titleImageView = [UIImageView new];
        _titleImageView.layer.masksToBounds = YES;
//        _titleImageView.contentMode = UIViewContentModeScaleAspectFit;
        _titleImageView.backgroundColor = getColor(@"666666");
        [self.contentView addSubview:_titleImageView];
        
        _titleLabel  = [[UILabel alloc]init];
        _titleLabel.font = DEF_FontSize_14;
        _titleLabel.textColor = getColor(textColor);
        _titleLabel.numberOfLines = 0;
        [self.contentView addSubview:_titleLabel];
        
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = getColor(dividerColor);
        [self.contentView addSubview:_lineView];
        
        [self layoutFrame];
    }
    return self;
}

- (void)layoutFrame{
    __weak __typeof(self)weakSelf = self;
    [self.titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10 / WIDTH_5S_SCALE);
        make.top.mas_equalTo(10 / WIDTH_5S_SCALE);
        make.bottom.mas_equalTo(- 10 / WIDTH_5S_SCALE);
        make.width.mas_equalTo(75 / WIDTH_5S_SCALE);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleImageView.mas_right).offset(10 / WIDTH_5S_SCALE);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0 / WIDTH_5S_SCALE);
        make.bottom.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 0 / WIDTH_5S_SCALE, 0.5));
    }];
}

- (void)setModel:(NSDictionary *)model{
    _model = model;
    [self.titleImageView sd_setImageWithURL:[NSURL URLOffsetIPWithString:model[@"first_picture"]]];
    self.titleLabel.attributedText = [self getAttributeName:model[@"c_name"] info:[NSString stringWithFormat:@"%@",model[@"quantity_purchased"]] money:[NSString stringWithFormat:@"%@",model[@"unit_price"]]];
}

- (NSAttributedString *)getAttributeName:(NSString *)name info:(NSString *)info money:(NSString *)money{
    NSMutableAttributedString *attStr = [NSMutableAttributedString new];

    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:name]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"数量  "]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:info]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"价格  ¥"]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:money]];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:6];//调整行间距
    
    [attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attStr.mutableString length])];
    
    return attStr;
}

@end
